package org.jeecg.common.system.vo;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 树节点model
 * @author 3hmzz
 */
@Data
public class TreeNode {
	private String key;//唯一
	private String value;//不唯一
	private String parentKey;
	private String title;
	private List<TreeNode> children;
	private Boolean isLeaf;
	private String icon;

	public List<TreeNode> getChildren() {
		if(children==null){
			children = new ArrayList<>();
		}
		return children;
	}

	public void setChildren(List<TreeNode> children) {
		this.children = children;
	}

	/**
	 * 父节点跟值一样就表示是同一个节点
	 */
	@Override
	public boolean equals(Object o) {
		if (this == o) return true;
		if (o == null || getClass() != o.getClass()) return false;
		TreeNode treeNode = (TreeNode) o;
		return Objects.equals(value, treeNode.value) &&
				Objects.equals(parentKey, treeNode.parentKey);
	}

	@Override
	public int hashCode() {
		return Objects.hash(value, parentKey);
	}
}
